var shopData = require('./shopData')();
var GameData = require('../../module/GameData')();

cc.Class({
    extends: cc.Component,

    properties: {
        title: cc.Label,
        shop_list: cc.ScrollView,
        shop_down_item: cc.Prefab,
        shop_goods_list:cc.ScrollView,
        shop_list_item:cc.Prefab,
        buy_layer:cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        GameData.shop=this;
        this.title.string = shopData.shop_title;
        this.content = this.shop_list.content;
        this.down_itemArr=[];
        this.init_down_list();
        this.initgoods();

        var fun=function(){};
        cc.find("loadbg").getComponent("loadbg").show(fun)
    },

    start() {

    },
    init_down_list() {
        var data = shopData.shop_down_data;
        for (var a = 0; a < data.length; a++) {
            let item = cc.instantiate(this.shop_down_item);
            this.down_itemArr.push(item);
            item.getComponent('shop_down_item').init(data[a]);
            this.content.addChild(item);
        }

    },
    /** 货架功能实现
    * time 2019/8/27
    * author:zzw
    * dsc:
    */
    initgoods(){
        let goodsdata=shopData.shop_center_data;
        for(var a=0;a<goodsdata.length;a++){
            let item=cc.instantiate(this.shop_list_item);
            item.getComponent('shop_list_item').init(goodsdata[a]);
            this.shop_goods_list.content.addChild(item);
        }
    },


    /*按钮回调方法*/
    callback(){
        console.log("ccc",this.shop_goods_list.content.position)
        // this.shop_goods_list.content.scrollTo(cc.v2())
    },
    scrollTo(){
        this.shop_goods_list.content.scrollTo(cc.v2(-300,0))
    },
    showBuy(data){
        this.buy_layer.getComponent("buy_layer").init(data);
        this.buy_layer.active=true;
    },
    back(){
        cc.director.loadScene("game_start");
    },
    // update (dt) {
        // console.log( this.shop_goods_list.content.position)

    // },
});
